package Notepad;

import java.util.Arrays;

public class SimpleNotepad implements Inotepad {

	private Page[] pages;
	public SimpleNotepad(int numberOfPages) {
		if(numberOfPages > 0)
		{
			this.pages = new Page[numberOfPages];
			for(int i = 0; i<pages.length; i++)
			{
				pages[i] = new Page(String.valueOf(i+1));
			}
		}
		else
		{
			System.out.println("Wrong input");
			System.exit(0);
		}
	}
	
	@Override
	public void addText(int pageNumber, String newText) {
		if(validatePage(pageNumber)){
		
			this.pages[pageNumber-1].addText(newText);
		}
	}

	private boolean validatePage(int pageNumber)
	{
		return pageNumber > 0  && pageNumber <= pages.length;
	}
	@Override
	public void replaceText(int page, String newText) {
		if(validatePage(page))
		{
			this.pages[page - 1].deleteText();
			this.pages[page - 1].addText(newText);
		}
	}

	@Override
	public void deleteText(Page selectedPage) {
		if(selectedPage != null)
		{
			for(int i = 0; i<pages.length; i++)
			{
				if(pages[i].equals(selectedPage))
					selectedPage.deleteText();
			}
		}
	}

	@Override
	public void LookThroughThePage() {
		for(int i = 0; i<pages.length; i++)
		{
			System.out.println(pages[i].lookThtough());
		}
		
	}

}
